<?php
namespace App;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;

define("ROOT_PATH", dirname(__DIR__) . "/");
class Log
{
    /**
     * @var Logger
     */
    private $log;
    private $logDir = "storage/logs/";

    public function __construct()
    {
        $fileName = date("Y-m-d").".log";
        $dateFormat = "Y-m-d H:i:s";
        $output = "{\"datetime\":\"%datetime%\",\"level\":\"%level_name%\",\"message\":\"%message%\",\"context\":%context%,\"extra\":%extra%}\r\n";
        $formatter = new LineFormatter($output, $dateFormat);
        $stream = new StreamHandler(ROOT_PATH.$this->logDir.$fileName, Logger::DEBUG);
        $stream->setFormatter($formatter);
        $this->log = new Logger('Tester');
        $this->log->pushHandler($stream);
    }

    /**
     * @param array $data
     * @return void
     * 错误日志
     */
    public function Err(Array $data){
        $this->log->error('hello', $data);
    }
}